<?php
/**
 * SmartyRenderer class definition
 *   
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MutantVole
 */
 
 /**
  * Base class for view renderers.
  * @package MutantVole
  * @subpackage Renderers
  */    
abstract class ViewRenderer {
	/**
     * Attach a view to be rendered
	 * @param iView $view
	 */  	
	public function AttachView(iView $view) {
		$this->views[] = $view;
	}
			
	/**
 	 * Set the template file for this renderer, if needed. Checks to make sure the file exists and returns false if
	 * it does not.  
	 * @param string $templateFile
	 * @return bool 
     */	
	public function SetTemplateFile($templateFile) {
		Contract::Precondition(!empty($templateFile), '$templateFile cannot be empty');
		
		if (!(file_exists($templateFile))) {
			return false;
		}
		
		return ($this->templateFile = $templateFile);
	}
	
	/**
     * Merge all the attached view properties into the properties of the renderer. Properties
     * that have already been merged will not be overwritten. 
     */	
	protected function CoalesceViews() {
		if (is_array($this->views)) {
			foreach ($this->views as $view) {
				if (is_array($view->properties)) {
					$this->properties = array_merge($view->properties, $this->properties);
				}
			}
		}
	}	

	protected $views = array();
	protected $properties = array();
	protected $templateFile;
}



?>